package com.wangxiang.shop.member.controller;

import java.util.*;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wangxiang.shop.member.entity.ReceiptEntity;
import com.wangxiang.shop.member.service.ReceiptService;
import com.wangxiang.common.utils.PageUtils;
import com.wangxiang.common.utils.R;



/**
 * 
 *
 * @author wangxiang
 * @email 2293672863@qq.com
 * @date 2022-04-10 15:46:03
 */
@RestController
@RequestMapping("member/receipt")
public class ReceiptController {
    @Autowired
    private ReceiptService receiptService;
    @RequestMapping("add")
    public R add(@RequestBody HashMap<String , String> map){
        System.out.println("数据"+map);
        int add = receiptService.add(map);
        if (add==0){
            return R.error("添加失败");
        }
        return R.ok().put("msg","添加成功");
    }
    @RequestMapping("list")
    public R list(@RequestBody HashMap<String , Integer> map){
        List<ReceiptEntity> list = receiptService.list(map.get("userId"));
        return R.ok().put("list",list);
    }
    @RequestMapping("update")
    public R update(@RequestBody HashMap<String , String> map){

        int update = receiptService.update(map);
        if (update==0){
            return R.error("修改失败");
        }
        return R.ok().put("msg","修改成功");
    }

    /**
     *删除为逻辑删除，把status置为2
     * @return
     */
    @RequestMapping("delete")
    public R delete(@RequestBody HashMap<String , Integer> map){
        int id = receiptService.delete(map.get("id"));
        if (id==0){
            return R.error("删除失败");
        }
        return R.ok().put("msg","删除成功");
    }

    /**
     * 根据购物
     * @param map
     * @return
     */
    @RequestMapping("receiptOrder")
    public R receiptOrder(@RequestBody HashMap<String , List<String>> map){
        System.out.println("数据"+map);
        map.get("cartIdList").forEach((item)->{
            System.out.println(item);
        });
        return null;
    }

}
